package view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import model.Teacher;
import controller.DeleteAbsence;
import controller.DeleteAbsenceTeacher;
import controller.DeleteTeacher;
import controller.EditTeacher;
import controller.NewTeacherAbsence;
import controller.TableModelAbsenceFromTeacher;

@SuppressWarnings("serial")
public class PanelTeacherDetails extends JPanel {

	private static PanelTeacherDetails single;
	private static PanelTeacherDetails instance;
	private Teacher currentTeacher;

	JTable AbsenceList;
	JScrollPane JSP;

	private JButton JBAdd = new JButton("Nieuwe absentie");
	private JButton JBEdit = new JButton("Wijzig absentie");
	private JButton JBdel = new JButton("verwijder absentie");
	private JButton Switch = new JButton("Week");
	private JButton Wijzig = new JButton("Wijzig");
	private JButton Delete = new JButton("Verwijder");
	private JButton DeleteConfirm = new JButton("Bevestigen");
	private JButton opslaan = new JButton("Opslaan");
	private JButton annuleren = new JButton("Annuleren");

	private JTextField JTname;
	private JTextField JTcode;
	private JTextField JTid = new JTextField();

	private String Sname;
	private String Scode;

	private JLabel JLcode = new JLabel("Code:");
	private JLabel JLname = new JLabel("Naam:");
	private JLabel JLcode2 = new JLabel();
	private JLabel JLname2 = new JLabel();
	
	public PanelTeacherDetails(Teacher t) {
		
		setBounds(0, 0, 860, 720);
		setLayout(null);

		JTname = new JTextField(Sname);
		JTcode = new JTextField(Scode);

		AbsenceList = new JTable(new TableModelAbsenceFromTeacher(t));
		JSP = new JScrollPane(AbsenceList);

		
		JBdel.setBounds(20, 450, 150, 30);
		JBAdd.setBounds(20, 500, 150, 30);
		JBEdit.setBounds(20, 550, 150, 30);
		Wijzig.setBounds(20, 200, 150, 30);
		opslaan.setBounds(20, 200, 150, 30);
		annuleren.setBounds(180, 200, 150, 30);
		Delete.setBounds(180, 200, 150, 30);
		DeleteConfirm.setBounds(180, 200, 150, 30);
		Switch.setBounds(720, 550, 50, 50);
		JLcode2.setBounds(150, 150, 100, 30);
		JLname2.setBounds(150, 100, 100, 30);
		JLcode.setBounds(20, 150, 100, 30);
		JLname.setBounds(20, 100, 100, 30);
		JTcode.setBounds(100, 150, 200, 30);
		JTname.setBounds(100, 100, 200, 30);
		JSP.setBounds(400, 100, 300, 500);

		JLcode2.setVisible(true);
		JLname2.setVisible(true);

		
		Delete.setVisible(true);
		DeleteConfirm.setVisible(false);
		opslaan.setVisible(false);
		annuleren.setVisible(false);
		JTname.setVisible(false);
		JTcode.setVisible(false);
		
		/*kleurtjes*/
		DeleteConfirm.setBackground(Color.RED);

		JBAdd.addActionListener(new NewTeacherAbsence(this));
		opslaan.addActionListener(new EditTeacher(this));
		JBdel.addActionListener(new DeleteAbsenceTeacher(this, t));
		Wijzig.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JLcode2.setVisible(false);
				JLname2.setVisible(false);
				Wijzig.setVisible(false);
				Delete.setVisible(false);
				DeleteConfirm.setVisible(false);

				JTcode.setVisible(true);
				annuleren.setVisible(true);
				opslaan.setVisible(true);
				JTname.setVisible(true);

			}
		});

		annuleren.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {

				Delete.setVisible(true);
				DeleteConfirm.setVisible(false);
				
				Wijzig.setVisible(true);
				JLcode2.setVisible(true);
				JLname2.setVisible(true);

				opslaan.setVisible(false);
				annuleren.setVisible(false);
				JTname.setVisible(false);
				JTcode.setVisible(false);

			}
		});

		Delete.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
			Delete.setVisible(false);
			DeleteConfirm.setVisible(true);
				
			}
		});
		DeleteConfirm.addActionListener(new DeleteTeacher(this));
		
		add(JBdel);
		add(JBAdd);
		add(JBEdit);
		add(Wijzig);
		add(Delete);
		add(DeleteConfirm);
		add(Switch);
		add(JLcode);
		add(JLname);
		add(JLcode2);
		add(JLname2);
		add(JSP);
		add(JTcode);
		add(JTname);
		add(opslaan);
		add(annuleren);

	}

	public JTable getAbsenceList() {
		return AbsenceList;
	}

	public void setAbsenceList(JTable absenceList) {
		AbsenceList = absenceList;
	}

	public JScrollPane getJSP() {
		return JSP;
	}

	public void setJSP(JScrollPane jSP) {
		JSP = jSP;
	}

	public JButton getAnnuleren() {
		return annuleren;
	}

	public void setAnnuleren(JButton annuleren) {
		this.annuleren = annuleren;
	}


	public static PanelTeacherDetails getInstance() {
		if (instance == null) {


			instance = new PanelTeacherDetails(null);
		}
		return instance;
	}

	
	
	
	public void selfDestroy() {
		single = null;
	}

	public static PanelTeacherDetails getSingle() {
		return single;
	}

	public static void setSingle(PanelTeacherDetails single) {
		PanelTeacherDetails.single = single;
	}

	public JTextField getJTName() {
		return JTname;
	}

	public void setJTName(JTextField name) {
		this.JTname = name;
	}

	public JTextField getJTCode() {
		return JTcode;
	}

	public void setJTCode(JTextField code) {
		this.JTcode = code;
	}

	public String getSname() {
		return Sname;
	}

	public void setSname(String Sname) {
		this.Sname = Sname;
	}

	public String getScode() {
		return Scode;
	}

	public void setScode(String Scode) {
		this.Scode = Scode;
	}

	public JLabel getJLcode() {
		return JLcode;
	}

	public void setJLcode(JLabel jlcode) {
		JLcode = jlcode;
	}

	public JLabel getJLname() {
		return JLname;
	}

	public void setJLname(JLabel jlname) {
		JLname = jlname;
	}

	public JTextField getJTid() {
		return JTid;
	}

	public void setJTid(JTextField jTid) {
		JTid = jTid;
	}

	public JButton getWijzig() {
		return Wijzig;
	}

	public void setWijzig(JButton wijzig) {
		Wijzig = wijzig;
	}

	public JButton getOpslaan() {
		return opslaan;
	}

	public void setOpslaan(JButton opslaan) {
		this.opslaan = opslaan;
	}

	public void updateTeacherDetail(Teacher t) {
		currentTeacher = t;
		JLcode.setName(t.getTeacher_code());
	}

	public Teacher getTeacher() {
		return currentTeacher;
	}

	public JLabel getJLcode2() {
		return JLcode2;
	}

	public void setJLcode2(JLabel jLcode2) {
		JLcode2 = jLcode2;
	}

	public JLabel getJLname2() {
		return JLname2;
	}

	public void setJLname2(JLabel jLname2) {
		JLname2 = jLname2;
	}

	public Teacher getCurrentTeacher() {
		return currentTeacher;
	}

	public void setCurrentTeacher(Teacher currentTeacher) {
		this.currentTeacher = currentTeacher;
	}

	public JButton getJBAdd() {
		return JBAdd;
	}

	public void setJBAdd(JButton jBAdd) {
		JBAdd = jBAdd;
	}

	public JButton getJBEdit() {
		return JBEdit;
	}

	public JButton getDelete() {
		return Delete;
	}

	public void setDelete(JButton Delete) {
		this.Delete = Delete;
	}
	
	public JButton getDeleteConfirm() {
		return DeleteConfirm;
	}

	public void setDeleteConfirm(JButton DeleteConfirm) {
		this.DeleteConfirm = DeleteConfirm;
	}

	public JTextField getJTname() {
		return JTname;
	}

	public void setJTname(JTextField jTname) {
		JTname = jTname;
	}

	public JTextField getJTcode() {
		return JTcode;
	}

	public void setJTcode(JTextField jTcode) {
		JTcode = jTcode;
	}

}
